<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml"
      xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>服务号-添加客服</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--插件样式-->
    <link rel="stylesheet" href="/dist/plugins/select2/select2.min.css">
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=86e2297f1">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=222aea35">

    <style type="text/css">
        .table-edit {
            width: 95%;
            margin-top: 20px !important;
            border: 0px;
        }

        .table-edit input[type=text] {
            border: 1px solid #e8e8e8;
        }

        .table-edit .tdL-salerManager {
            width: 18%;
            text-align: right;
            padding-right: 5px !important;
            height: 45px;
            border: 0px;
        }

        .table-edit .tdR-salerManager {
            width: 82%;
            height: 45px;
            border: 0px;
        }

        .table-edit .tdL-bigAreaManager {
            width: 18%;
            text-align: right;
            padding-right: 5px !important;
            height: 36px;
            border: 0px;
        }

        .table-edit .tdR-bigAreaManager {
            width: 82%;
            height: 36px;
            border: 0px;
        }

        .table-edit textarea {
            height: 60px;
            border: 1px solid #e8e8e8;
            padding-top: 5px !important;
        }

        .table-area input[type=number] {
            border: 0px;
            text-align: center;
        }

        .table-area td {
            height: 25px;
            line-height: 25px;
            border-bottom: 1px solid #e8e8e8;
            border-right: 1px solid #e8e8e8;
        }

        .table-area td .number {
            width: 22px;
            border: 0px;
            text-align: left;
        }

        .table-area td .number-span {
            vertical-align: middle;
            width: 15px;
            height: 15px;
            line-height: 12px;
            text-align: center;
            display: inline-block;
            cursor: pointer;
        }

        .table-edit select {
            border: 1px solid #e8e8e8;
        }

        .table-edit .day-content {
            width: 56%;
            float: right;
            height: 30px;
            line-height: 30px;
            border: 1px solid #e8e8e8;
            border-left: 0px;
        }

        .table-area .area-name-font {
            text-align: left;
            text-indent: 5px;
        }

        .table-area .row-height {
            height: 25px;
            line-height: 25px;
            overflow: hidden;
            word-break: break-all;
            word-wrap: break-word;
            text-align: left;
        }

        .table-area input {
            text-align: center;
        }
        .select2-container--bootstrap .select2-selection--single .select2-selection__arrow {
            height: 26px;
            position: absolute;
            top: 1px;
            right: 1px;
            width: 20px;
        }
        .select2-container--bootstrap .select2-selection--single .select2-selection__arrow b {
            border-color: #888 transparent transparent transparent;
            border-style: solid;
            border-width: 5px 4px 0 4px;
            height: 0;
            left: 50%;
            margin-left: -4px;
            margin-top: -2px;
            position: absolute;
            top: 50%;
            width: 0;
        }
        .select2-container--bootstrap .select2-selection--single, .select2-selection .select2-selection--single {
            border: 1px solid #d2d6de;
            border-radius: 0;
            padding: 6px 12px;
            height: 25px !important;
        }
        .select2-container--bootstrap .select2-selection--single .select2-selection__arrow {
            height: 20px;
            right: 3px;
        }
        .select2-container--bootstrap .select2-selection--single .select2-selection__rendered {
            line-height: 22px !important;
        }
    </style>
</head>
<body>
    <div class="south" style="height:50px;line-height:30px;text-align:center;">
        <input type="button" value="添加" class="btn oaBtn btn-sm" @click="add()"/>
    </div>
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=8e743a31"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=54c6b89c"></script>
<script type="text/javascript" src="/dist/plugins/select2/select2.min.js"></script>
<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<script type="text/javascript" src="/dist/plugins/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
//    var api = frameElement.api, W = api.opener;
    var edit = new Vue({
        el: "#edit",
        data: {
            firstName:"",
            isFirst:true,
            original_name:"",
            item:"",
            data:""
        },
        methods: {
            add: function () {

                if (this.isFirst){//    以及菜单
                    if (this.firstName == "") {
                        alert("请填写菜单名称");
                        return;
                    }
                }else {//   二级菜单
                    if (this.item.name == "") {
                        alert("请填写菜单名称");
                        return;
                    }
                    if (this.item.url == "") {
                        alert("请填写跳转url");
                        return;
                    }
                }
                var buttons = this.data["button"];
                if (this.isFirst){//    一级菜单
                    for (var i in buttons){
                        var temp_name = buttons[i]["name"];
                        if(temp_name == this.original_name){
                            this.data["button"][i]["name"] = this.firstName;
                        }
                    }
                }else {//   二级菜单
                    for (var i in buttons){
                        var subButtons = buttons[i]["sub_button"];
                        for(var j in subButtons){
                            var name = subButtons[j]["name"];
                            if(name == this.original_name){
                                this.data["button"][i]["sub_button"][j]["name"] = this.item.name;
                                this.data["button"][i]["sub_button"][j]["url"] = this.item.url;
                            }
                        }
                    }
                }
                $.wyui.postMethod("/serviceAccountMenu/createMenu.json", this.data, function (r) {
                    console.log(r);
                    if(r["errcode"] == "0"){
                        alert("操作成功");
                        parent.app.refresh();
//                        api.close();
                    }else {
                        alert("操作失败，请重试！");
                    }
                });
            }
        },
        mounted: function () {
            //  内容处理
            var isFirst = $.wyui.page.urlParams.isFirst;
            this.isFirst = isFirst;
            if (isFirst == "true"){//    一级菜单
                this.isFirst = true;
                var name = $.wyui.page.urlParams.name;
                this.firstName = name;
                this.original_name = name;
            }else {//   二级菜单
                this.isFirst = false;
                var item_string = $.wyui.page.urlParams.item;
                this.item = JSON.parse(item_string);
                this.original_name = this.item.name;
            }
            var data_string = $.wyui.page.urlParams.data;
            this.data = $.parseJSON(data_string);
        }
    });
</script>
</body>
</html>